home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 1 / ETO Development Tools 1.iso / Essentials / MacApp Documentation / MacApp AppleLink Messages / MacApp.Tech$ 5⁄4⁄90 / 1229-Clearing the Clipboa-May90 < prev    next >
Encoding:
Text File  |  1990-05-04  |  4.2 KB  |  105 lines  |  [TEXT/GEOL]

  1. Item    9478958                         1-May-90        15:21PDT
  2.  
  3. From:   D5284                           BDM Int'l, Ann Confer,PRT
  4.  
  5. To:     MACAPP.TECH$                    MacApp Technical
  6.  
  7. Sub:    Clearing the Clipboard
  8.  
  9.    We are developing a MacApp application that must clear the contents of the
  10. clipboard whenever the application is Quit.  Although this is not a common
  11. practive in Macintosh applications it is being done at the request of the
  12. customer.  When switching between open application in MultiFinder, the contents
  13. are not to be cleared.
  14.  
  15.     The problem sounds simple but has not been easy to solve.  I have managed t
  16. get it to work in a particular scenario but in another.  If I perform a Copy
  17. from within my application, switch to another application (to paste, for
  18. example), switch back to my application, and then quit, the system clipboard is
  19. not cleared.  However, if I perform a second copy operation after switching
  20. back, and then quit, the system clipboard is cleared.  Regardless of the
  21. mechanism I try for clearing the clipboard, these scenarios remain the same.
  22. Is there something basic that I am overlooking that prohibits me from doing
  23. this?
  24.  
  25.    I have tried two basic approaches.  First of all, I tried using the Toolbox
  26. calls ZeroScrap, PutScrap, etc directly. As the very last line(s) in the main
  27. program of the MacApp application, I tried calling ZeroScrap and then inserting
  28. nothing or blanks into the Clipboard.  This did not work.  I also tried adding
  29. such calls in overridden versions of methods such as the MainEventLoop.  I even
  30. tried setting the scrap state parameter to not initialized.
  31.  
  32.    Currently (see below), I have overridden TApplication.MainEventLoop to perfo
  33. all of the normal event loop processing and then to call my ClearClipboard
  34. procedure.  This procedure creates a new empty view and assigns it to
  35. gClipView.  Then when AboutToLoseControl is called, my empty view is written to
  36. the desk scrap.  Unfortunately, this only works if a copy is done after
  37. reentering my application (as described above).  I tried mimicing the
  38. operations performed by a copy command in ClearClipboard and then creating my
  39. empty clipboard view, but there was no difference.
  40.  
  41.  
  42. If anyone has any ideas, I would appreciate it. Thanks.  Ann Confer
  43.  
  44.  
  45.  
  46.  
  47. (* Here is the ClearClipboard procedure called from MainEventLoop  Not all
  48. attempts are included here; only the most recent version. Sorry that the format
  49. got messed up when I copied it in here. *)
  50.  
  51. PROCEDURE ClearClipboard;
  52.  
  53. VAR    theScrapPtr: PScrapStuff; (* old *)
  54.    theScrap: ScrapStuff;
  55.    blank, theString: Str255;
  56.    emptyClipView: TTEView;
  57. theHandle: Handle;
  58. acommand:  TCutCopyCommand;
  59.  
  60.    (* begin ClearClipboard *)
  61. BEGIN
  62. {$IFC qDebug}writeln('***Entering ClearClipboard');{$ENDC}
  63.  
  64.    (* new attempt to mimic copy command - no diff *)
  65.    IF (gLastCommand = NIL) THEN
  66. BEGIN
  67. New(emptyClipView);
  68.    FailNIL(emptyClipView);
  69. emptyClipView.ITEView(NIL, NIL,gZeroVPt, gZeroVPt,sizeFixed, sizeFixed,
  70. gZeroRect,gSystemStyle,teJustLeft,kWithoutStyle, TRUE);
  71. emptyClipView.fAcceptsChanges := FALSE;
  72.    acommand := emptyClipView.DoMakeEditCommand(cCopy);
  73.    acommand.DoIt;
  74. END; (* end code for new attempt - no diff *)
  75.  
  76.    (* commit the last clipboard-related command so the application wont    writ
  77. "old" data to the clipboard when application is processed by
  78. AboutToLoseControl *)
  79.    IF (gLastCommand <> NIL) & (gLastCommand.fChangesClipboard) THEN
  80. gAnalysisApplication.CommitLastCommand;
  81.        (* create an empty clipboard view *)
  82.    New(emptyClipView);
  83.    FailNIL(emptyClipView);
  84.    emptyClipView.ITEView(NIL, NIL,gZeroVPt, gZeroVPt,sizeFixed, sizeFixed,
  85. gZeroRect,gSystemStyle,teJustLeft,kWithoutStyle, TRUE);
  86. emptyClipView.fAcceptsChanges := FALSE;
  87.  
  88.    (* invoke TTEView.StuffText to stuff empty text handle into the view *)
  89.    (* ** tried setting handle to blanks rather than empty, no diff *)
  90. theHandle := NewPermHandle(0);
  91.    FailNil(theHandle);
  92.    theString := ' ';
  93. (* invoke Mac OS Utility PtrAndHand to append the string to the view text *)
  94. FailOSErr(PtrAndHand(@theString[1], theHandle, Length(theString) ));
  95. emptyClipView.StuffText(theHandle);
  96. gAnalysisApplication.ClaimClipboard(emptyClipView);
  97.    gClipWrittenToDeskScrap := FALSE;
  98.  
  99.    {$IFC qDebug} writeln('***Exiting ClearClipboard');{$ENDC}
  100.  
  101. (* end ClearClipboard *)
  102.    END;
  103.  
  104.  
  105.